//数据字典
const map = {
    sex: {
        1: '男',
        2: '女'
    },
    operateType: {
        1: "登陆",
        2: "查看",
        3: "编辑",
        4: "删除",
        5: "新增"
    },
    suspensionState: {
        1: "否",
        2: "是"
    }

}
//枚举转化
function convertData(datas, keys = []) {
    if (keys.length > 0) {
        datas.forEach(data => {
            keys.forEach(key => {
                data[key + "_text"] = map[key][data[key]];
            })
        });
    }
    return datas
}


export default {
    methods: {
        //加载分页数据
        loadPage(res, keys) {
            this.tableData = convertData(res.data.data.records, keys);
            this.search.size = res.data.data.size;
            this.search.current = res.data.data.current;
            this.total = res.data.data.total;
        },
        //加载列表数据
        loadList(res, keys) {
            this.tableData = convertData(res.data.data, keys)
            if (this.tableData.length > 0) {
                this.tableData.forEach(e => e.hasChildren = true);
            }
        },
        //刷新指定行
        refreshRow(index, row) {
            this.$set(index, row);
        },
        getTextValue(key, num) {
            return map[key][num]
        }
    }
}